
function trim(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}


function checkfolder(eventObj, obj){
	var keyCode
	var str=obj.value

	if (document.all){keyCode=eventObj.keyCode}
	else{keyCode=eventObj.which}
	
	if(keyCode==32){return true} // 0..9
	if(keyCode>=48 &&  keyCode<=57){return true} // 0..9
	if(keyCode>=65 &&  keyCode<=90){return true} // A..Z
	if(keyCode>=97 &&  keyCode<=122){return true} // a..z
	
	return false
}

function checkint(eventObj, obj){
	var keyCode
	var str=obj.value

	if (document.all){keyCode=eventObj.keyCode}
	else{keyCode=eventObj.which}

	if(keyCode==46){return false}
	if((keyCode<48 || keyCode >58)   &&   (keyCode != 46) && (keyCode != 13)){return false}
	return true
}

function checkdecimal(eventObj, obj){
	var keyCode
	var str=obj.value

	if (document.all){keyCode=eventObj.keyCode}
	else{keyCode=eventObj.which}

	if(keyCode==46){if (str.indexOf(".")>0){return false}}
	if((keyCode<48 || keyCode >58)   &&   (keyCode != 46)){return false}
	return true
}


function checkdate(eventObj, obj){

	var keyCode
	var str=obj.value
	
	// Check For Browser Type
	if (document.all){keyCode=eventObj.keyCode}
	else{keyCode=eventObj.which}

	if(keyCode==13){
		kp (eventObj, obj);
		return false;
	}

	if(keyCode==47){return false}

	if((keyCode<48 || keyCode >58)){return false}
	return true
}
	
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isDate (day,month,year) {
	var today = new Date();
	var test = null;
	
	if (!day) return false;
	
	try{var test = new Date(year,month,day);}
	catch(er){return false;}
			
	if ( (y2k(test.getYear()) == year) &&	(month == test.getMonth()) &&	(day == test.getDate()) ){
		return true;
	}else{
		return false;
   } 	
	
}

function sepDate(field){

	 var frmt=new String(field.value);

	 if (frmt.indexOf("/")==-1){
		
		if (frmt.length==8){
			field.value = frmt.substr(0,2)+ "/" + frmt.substr(2,2)+"/" + frmt.substr(4,4);
		}else if (frmt.length==4){
			var d;
			d = new Date();
			field.value = frmt.substr(0,2)+ "/" + frmt.substr(2,2)+"/" + d.getYear();
		}else if ((frmt.length==1)||(frmt.length==2)){
			var d;
			d = new Date();
			mm = "" + (d.getMonth()+1)
			
			if (mm.length == 1 ){
				mm = "0"+mm
			} 
			 
			if (frmt.length == 1 ){
				frmt = "0"+frmt
			} 

			field.value = frmt.substr(0,2)+ "/" + mm +"/" + d.getYear();
			
		}else if (frmt.length==6){
			y = frmt.substr(4,2)
			if (y > "12"){
				th="19" 
			}else{
				th="20"
			}			
			field.value = frmt.substr(0,2)+ "/" + frmt.substr(2,2)+"/" + th + y;
		}
	 }

	if (field.value != ""){
		if (!chkIfDate(field.value)){
			alert("Wrong Date")
			field.value="";
			field.focus()
		}
	}	
			 
}
	
function chkIfDate(date){
	try{
		
		
		var day 	= 	parseInt("1"+date.substr(0,2))-100;
		var month	=	parseInt("1"+date.substr(3,2))-100;
		var year	=	parseInt(date.substr(6,4));
		
		return isDate(day,month-1,year);
	}catch(er){return false;}	
}	

function autoTab(input,len, e) {
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		try{input.value = input.value.slice(0, len);}catch(e){}
		try{input.form[(getIndex(input)+1) % input.form.length].focus();}catch(e){}
		try{input.form[(getIndex(input)+1) % input.form.length].select();}catch(e){}
		
	}

	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;
}
